<form class="form-horizontal" role="form" method="post" action="<?=site_url('orderaff/index') ?>"> 
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Tình trạng đơn hàng</label>    
    <div class="col-sm-3">
      <select class="form-control" name="status">
        <option value="">--Tất cả--</option>
        <option value="pending" <?=($order_status == 'pending') ? 'selected' : '' ?>>Đang chờ</option>
        <option value="failed"  <?=($order_status == 'failed') ? 'selected' : '' ?>>Thất bại</option>
        <option value="processing"  >Đang xử lý</option>
        <option value="completed" >Hoàn tất</option>
        <option value="refund"  >Hoàn tiền</option>
        <option value="canceled"  >Hủy</option>
      </select>
    </div>    
    <div class="container">
      <div class="col-sm-6" style="height:75px;">
         <div class='col-md-5' style="margin-right:10px;">
              <div class="form-group">
                  <div class='input-group date' id='datetimepicker8'>
                      <input type='text' name="fromDate" class="form-control" placeholder="Chọn từ ngày" value="<?=isset($fromDate) ? $fromDate : "" ?>" />
                      <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                      </span>
                  </div>
              </div>
          </div>              
          <div class='col-md-5' style="">
              <div class="form-group">
                  <div class='input-group date' id='datetimepicker9'>
                      <input type='text' name="toDate" class="form-control" placeholder="tới ngày" value="<?=isset($toDate) ? $toDate : "" ?>"/>
                      <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                      </span>
                  </div>
              </div>
          </div>
      </div>    
      <script type="text/javascript">
          $(function () {
              $('#datetimepicker8').datetimepicker();
              $('#datetimepicker9').datetimepicker();
              $("#datetimepicker8").on("dp.change",function (e) {
                 $('#datetimepicker9').data("DateTimePicker").setMinDate(e.date);
              });
              $("#datetimepicker9").on("dp.change",function (e) {
                 $('#datetimepicker8').data("DateTimePicker").setMaxDate(e.date);
              });
          });
      </script>
      <button type="submit" class="btn btn-primary">Tìm kiếm</button></td>    
    </div> 
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Số điện thoại</label>    
    <div class="col-sm-3">
      <input type="text" name="phone" class="form-control" id="inputPassword3" placeholder="Nhập số điện thoại khách hàng.." value="<?=isset($phone_number) ? $phone_number : "" ?>">
    </div>
    <div class="col-sm-3">
      <input type="text" name="customer" class="form-control" id="inputPassword3" placeholder="Nhập tên khách hàng.." value="<?=isset($customer_name) ? $customer_name : "" ?>">
    </div>
  </div>  
</form>

<div class="table-responsive">
  <table class="table table-bordered table-striped table-hover">
    <thead>
      <tr class="success" align="center">
        <td>Sản phẩm</td>               
        <td>Khách hàng</td>
        <td>Số điện thoại</td>
        <td>Địa chỉ</td>
        <td>Số lượng</td>                    
        <td>Tình trạng</td>            
        <td>Ngày tạo</td>           
      </tr>
    </thead>
    <tbody>      
      <?php 
        $i = 1;     
        foreach ($orders as $row):                    
          $product_image = !empty($row['product_image']) ? '<img src="'.base_url('uploads/image/products/'.$row['product_image']).'" class="img-responsive" alt="Responsive image" style="width: 80%">' : '';
          echo '<tr align="center">
              <td style="width:20%"> Code: '.
                $row['code'].'<br>#'.
                $row['order_id'].'<br>'.
                $row['product_title'].'<br>               
                '.$product_image.'
                </td>              
              <td>'.$row['customer_name'].'</td>
              <td>'.$row['customer_phone'].'</td>
              <td>'.$row['address'].'</td>
              <td>'.$row['quantity'].'</td>
              <td>'.$row['status'].'</td>
              <td>'.$row['created_at'].'<br>Giá: '.$row['product_price'].'</td>                          
              </tr>';               
          $i++;
        endforeach;
      ?>
    </tbody>
  </table>
  <?= !empty($paging_orders) ? "<div class='pull-right'><span>Tổng cộng: $total đơn hàng</span><br>$paging_orders</div>" : "" ?>  
</div>  